package com.guchenbo.springboot.aop;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

// 1、需要有TransactionManagement的bean，才能开启事务支持
// 2、这里定义了一个Gcb的demo TransactionManagement
@SpringBootApplication
public class DemoApplication {

    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 1000, TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<>(10));


    static final int SHARED_SHIFT   = 16;
    static final int SHARED_UNIT    = (1 << SHARED_SHIFT);
    static final int MAX_COUNT      = (1 << SHARED_SHIFT) - 1;
    static final int EXCLUSIVE_MASK = (1 << SHARED_SHIFT) - 1;

    /** Returns the number of shared holds represented in count  */
    static int sharedCount(int c)    { return c >>> SHARED_SHIFT; }
    /** Returns the number of exclusive holds represented in count  */
    static int exclusiveCount(int c) { return c & EXCLUSIVE_MASK; }

    public static void main(String[] args) {
//        for (int i = 0; i < 3; i++) {
//            final int finalI = i;
//            threadPoolExecutor.submit(()->{
//
//                try {
//                    //                    lockW.lock();
//                    System.out.println("start");
//                    new WaitClientCloseServer().start(10000 + finalI);
//
//                    //                    System.out.println("lock");
//                    //                    Thread.sleep(3000);
//                    //                    lockW.lock();
//                    //                    System.out.println("re lock");
//                    //                    lockW.unlock();
//                } finally {
//                }
//
//            });
//        }
//
//        SpringApplication.run(DemoApplication.class, args);

        System.out.println(exclusiveCount(65536));
        System.out.println(sharedCount(65536));



    }
}
